#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
#include <QDomDocument>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::faireActionOuvrir() {
    QString fileName = QFileDialog::getOpenFileName(this, tr("Choisir un document Algobox"),
                                                     QDir::homePath()+"/Documents/Documents de test/",
                                                     tr("Fichiers (*.alg)"));
    if (fileName.isEmpty()) {
        return;
    }
    QFile file(fileName);
    if (NOT file.open(QFile::ReadOnly | QFile::Text)) {
        QMessageBox::warning(this, tr("Converter"),
                             tr("Cannot read file %1:\n%2.")
                             .arg(fileName)
                             .arg(file.errorString()));
        return;
    }
    QTextStream stream(&file);
    QString content = stream.readAll();
    ui->plainTextEdit->setPlainText(content);
    statusBar()->showMessage(tr("File loaded"), 2000);
    QDomDocument doc("mydocument");
    if (doc.setContent(content,true)) {
    }
    file.close();
    return;
}

void MainWindow::faireActionTraduire()
{
    qDebug() << "message de traduction";
}

